//
//  AppController.h
//  This file is part of D&D Manager
//
//  Created by Matthew Hutton on 01/10/2006.
//
//
//D&D Manager, a D&D Character and battle management program.
//Copyright (C) 2007, Matthew Hutton
//
//This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License along with this program; if not, write to:
//The Free Software Foundation, Inc.,
//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

/* AppController */
#import <Cocoa/Cocoa.h>
//other controllers.
#import "SpellClassController.h"
#import "DiceRollerController.h"
#import "GrantXPController.h"
#import "BattleController.h"
#import "NSManagedObjectExtended.h"
#import "MenuController.h"
#import "SpellSVController.h"
#import "CharacterClassController.h"
//value transformers
#import "ChooseClass.h"
#import "ScoreToBonus.h"
#import "ToYesNo.h"
#import "RandomNumbers.h"
#import "DexACBonus.h"
#import "MaxRank.h"
#import "GoodOrEvil.h"
#import "LastsOverARound.h"
#import "AttackBonus.h"
#import "Damage.h"
#import "WeaponType.h"
#import "GreyBlackColour.h"
//#import "GreyWhiteColour.h"
#import "NotRangedWeapon.h"
#import "Spells.h"
#import "ArmourClass.h"
#import "StrengthWeaponBonus.h"
#import "NotThree.h"
#import "AbilityAttackBonus.h"
#import "LevelOrHD.h"
#import "XValue.h"

@interface AppController : NSObject{
	//stores of characters for each party.
	//converts a score to a bonus
	ChooseClass *chooseClass;
	ScoreToBonus *sToB;
	DexACBonus *dexACbonus;
	ToYesNo *toYN;
	MaxRank *maxRank;
	GoodOrEvil *goodOrEvil;
	LastsOverARound *lasts;
	Damage *damT;
	AttackBonus *attackB;
	WeaponType *wType;
	//GreyWhiteColour *gwc;
	NotRangedWeapon *nrw;
	Spells *sp;
	ArmourClass *ac;
	StrengthWeaponBonus *strWeapBonus;
	NotThree *n3;
	AbilityAttackBonus *abilityAttackBonus;
	LevelOrHD *lvlOrHD;
	//the managedObjectModel.
	NSManagedObjectModel *model;
	NSManagedObjectContext *mObjC;
	//end
	IBOutlet NSWindow *mainScreen;
	IBOutlet NSTableView *characterTable;
	IBOutlet NSButton *removeCharacterButton;
	//Saving Throws.
	//IBOutlet NSTextField *fortitudeAbilityBonus;
	//IBOutlet NSTextField *reflexAbilityBonus;
	//IBOutlet NSTextField *willAbilityBonus;
	//HP
	IBOutlet NSTextField *conHPBox;
	//Initiative
	//IBOutlet NSTextField *initMiscBonus;
	//Armour Class
	IBOutlet NSTextField *armourCheckPenalty;
	IBOutlet NSTextField *acDexterity;
	IBOutlet NSPopUpButton *maxDexBonus;
	//Character Class Stuff
	IBOutlet NSPopUpButton *charClassNameQuick;
	IBOutlet NSPopUpButton *charClassName1;
	IBOutlet NSPopUpButton *charClassName2;
	IBOutlet NSPopUpButton *charClassName3;
	IBOutlet NSTextField *level1;
	IBOutlet NSTextField *level2;
	IBOutlet NSTextField *level3;
	IBOutlet NSWindow *levelUpSheet;
	IBOutlet NSTextField *levelUpBlurb;
	IBOutlet NSTextField *extraHPTF;
	IBOutlet NSTextField *extraHPBlurb;
	IBOutlet NSTextField *levelUpSkillPoints;
	IBOutlet NSTextField *levelUpFeatsLabel;
	IBOutlet NSTextField *levelUpFeats;
	//etc on basics2
	IBOutlet NSTextField *fortitudeBase;
	IBOutlet NSTextField *reflexBase;
	IBOutlet NSTextField *willBase;
	IBOutlet NSTextField *baseAttackBonus;
	IBOutlet NSTextField *fortitudeBaseQuick;
	IBOutlet NSTextField *reflexBaseQuick;
	IBOutlet NSTextField *willBaseQuick;
	IBOutlet NSTextField *baseAttackBonusQuick;
	IBOutlet NSButton *hastedButton;
	IBOutlet NSButton *slowedButton;
	//Battle Stuff
	//Add/Edit Char from Battle Screen.
	IBOutlet NSTableView *characterTableBattle;
	IBOutlet NSButton *addToMainParty;
	IBOutlet NSButton *addToEnemyParty;
	IBOutlet NSButton *addCharButton;
	IBOutlet NSTabView *mainTabView;
	//parties (party options)
	IBOutlet NSPopUpButton *savedPartys1;
	IBOutlet NSPopUpButton *savedPartys2;
	IBOutlet NSButton *deleteParty1;
	IBOutlet NSButton *deleteParty2;
	IBOutlet NSButton *renameParty1;
	IBOutlet NSButton *renameParty2;
	IBOutlet NSWindow *renameSheet;
	IBOutlet NSTextField *renameTF;
	IBOutlet NSTextField *renameTypeTF;
	IBOutlet NSArrayController *partyController;
	//tab views.
	IBOutlet NSTabView *characterTabView;
	IBOutlet NSTabView *abilitiesTabView;
	BOOL soundPlaying;
	//battle controllers.
	IBOutlet NSArrayController *characterController;
	IBOutlet NSArrayController *mainPartyController;
	IBOutlet NSArrayController *enemyPartyController;
	IBOutlet NSArrayController *theBattleController;
	NSManagedObject *battleStore;
	//weapons
	IBOutlet NSArrayController *weaponController;
	IBOutlet NSTableView *weaponTableView;
	IBOutlet NSTextField *weaponNameField;
	IBOutlet NSTabView *weaponTypeTabView;
	IBOutlet NSTextField *defaultWeaponBox;
	IBOutlet NSTextField *strWeapField;
	IBOutlet NSTextField *attackBonusTF;
	IBOutlet NSPopUpButton *magicPlusMS;
	IBOutlet NSPopUpButton *magicPlusQuick;
	IBOutlet NSTableView *quickWeaponsTable;
	IBOutlet NSPopUpButton *criticalTypeQuick;
	//skills
	IBOutlet NSArrayController *skillsController;
	IBOutlet NSTextField *difficultyClass;
	IBOutlet NSTableView *skillTable;
	IBOutlet NSButton *armourCheckButton;
	IBOutlet NSTextField *skillNameTF;
	IBOutlet NSPopUpButton *skillClassChooser;
	IBOutlet NSTextField *skillPointsLeftTF;
	//skills tester
	IBOutlet NSButton *party1Button;
	IBOutlet NSButton *party2Button;
	IBOutlet NSButton *noTemplatesButton;
	IBOutlet NSButton *andOrToggle;
	IBOutlet NSTableView *skillsToChooseTable;
	IBOutlet NSTextField *stDifficultyClassBox;
	//IBOutlet NSArrayController 
	//link to new controller.
	SpellClassController *scController;
	DiceRollerController *diceController;
	GrantXPController *grantXPController;
	BattleController *battleController;
	SpellSVController *svController;
	CharacterClassController *ccController;
	IBOutlet NSArrayController *characterClassController;
	IBOutlet NSArrayController *spellController;
	//turn undead
	IBOutlet NSTextField *turnUndeadCasterLevel;
	//feats
	IBOutlet NSArrayController *featsController;
	IBOutlet NSButton *featActiveButton;
	IBOutlet NSTableView *featTable;
	IBOutlet NSTableView *abilTable;
	IBOutlet NSTabView *featTypeStuff;
	IBOutlet NSWindow *featToSkillSheet;
	IBOutlet NSWindow *featToWeaponSheet;
	IBOutlet NSWindow *featToSpellSheet;
	IBOutlet NSWindow *featToFeatSheet;
	IBOutlet NSTextField *featUsesLeft;
	//feat objects.
	IBOutlet NSPopUpButton *featWType;
	IBOutlet NSTextField *featMaxRange;
	IBOutlet NSPopUpButton *featType;
	IBOutlet NSPopUpButton *featWMod1;
	IBOutlet NSPopUpButton *featWMod2;
	IBOutlet NSPopUpButton *featWKey1;
	IBOutlet NSPopUpButton *featWKey2;
	IBOutlet NSPopUpButton *featMod1;
	IBOutlet NSPopUpButton *featMod2;
	IBOutlet NSPopUpButton *featMod3;
	IBOutlet NSPopUpButton *featMod4;
	IBOutlet NSPopUpButton *featKey1;
	IBOutlet NSPopUpButton *featKey2;
	IBOutlet NSPopUpButton *featKey3;
	IBOutlet NSPopUpButton *featKey4;
	IBOutlet NSPopUpButton *featSpellKey;
	IBOutlet NSPopUpButton *featSpellMod;
	IBOutlet NSPopUpButton *featSpellLevelMod;
	IBOutlet NSPopUpButton *featAffects;
	IBOutlet NSTextField *xModTF;
	IBOutlet NSButton *abilActiveButton;
	IBOutlet NSPopUpButton *abilWType;
	IBOutlet NSTextField *abilMaxRange;
	IBOutlet NSPopUpButton *abilType;
	IBOutlet NSPopUpButton *abilWMod1;
	IBOutlet NSPopUpButton *abilWMod2;
	IBOutlet NSPopUpButton *abilWKey1;
	IBOutlet NSPopUpButton *abilWKey2;
	IBOutlet NSPopUpButton *abilMod1;
	IBOutlet NSPopUpButton *abilMod2;
	IBOutlet NSPopUpButton *abilMod3;
	IBOutlet NSPopUpButton *abilMod4;
	IBOutlet NSPopUpButton *abilKey1;
	IBOutlet NSPopUpButton *abilKey2;
	IBOutlet NSPopUpButton *abilKey3;
	IBOutlet NSPopUpButton *abilKey4;
	IBOutlet NSPopUpButton *abilSpellKey;
	IBOutlet NSPopUpButton *abilSpellMod;
	IBOutlet NSPopUpButton *abilSpellLevelMod;
	IBOutlet NSPopUpButton *abilAffects;
	IBOutlet NSPopUpButton *abilFilter;
	int skillNo;
	//portrait
	IBOutlet NSImageView *portraitBox;
	//immunities.
	IBOutlet NSWindow *immunitiesPanel;
	IBOutlet NSArrayController *immunitiesController;
	IBOutlet NSPopUpButton *immResistance;
	IBOutlet NSPopUpButton *immPercentage;
	IBOutlet NSTextField *immValueTF;
	//resting
	IBOutlet NSMatrix *restOrRestore;
	IBOutlet NSWindow *restSheet;
	IBOutlet NSButton *party1Button2;
	IBOutlet NSButton *party2Button2;
	IBOutlet NSButton *noTemplatesButton2;
	IBOutlet NSButton *andOrToggle2;
	//converting files.
	IBOutlet NSWindow *fileConversionSheet;
	IBOutlet NSButton *fileConversionContinue1;
	IBOutlet NSButton *fileConversionContinue2;
	NSString *fileNameStore;
	//quick character creation
	IBOutlet NSWindow *quickCreateSheet;
	IBOutlet NSButton *quickAddToParty1;
	IBOutlet NSButton *quickAddToParty2;
	//log sheet
	IBOutlet NSWindow *logSheet;
	//menuController
	MenuController *menuController;
	BOOL needsCustomCharToDisplay;
	BOOL postModelSetupDone;
	//file preferences
	IBOutlet NSWindow *fileOptionsSheet;
}
//returning characters/spells
-(IBAction)characterSearchUnderway:(id)sender;
-(NSArrayController *)characterController;
//returning methods.
-(BattleController *)battleController;
//Ability Change Methods.
-(IBAction)strengthChanged:(id)sender;
-(IBAction)dexterityChanged:(id)sender;
-(IBAction)constitutionChanged:(id)sender;
-(IBAction)intelligenceChanged:(id)sender;
-(IBAction)wisdomChanged:(id)sender;
-(IBAction)charismaChanged:(id)sender;
-(int)conHPBonusForCharacter:(NSManagedObject *)obj;
-(IBAction)setUpArmourClassFromQuick:(id)sender;
//XP methods
-(IBAction)setLevelOrXP:(id)sender;
-(void)setLevelOrXPForCharacter:(NSManagedObject *)obj
		  withGeneralProcessing:(BOOL)general
		  withFurtherProcessing:(BOOL)further
					 forClassNo:(int)classNo;
-(IBAction)cancelLevelUpSheet:(id)sender;
-(IBAction)closeLevelUpSheet:(id)sender;
-(IBAction)setUpLevelFromQuick:(id)sender;
-(int)getCharacterLevelForChar:(NSObject *)obj
					  forClass:(NSString *)theClass;
-(void)reloadDomainOptions;
-(IBAction)characterClassChanged:(id)sender;
-(void)classChangingDidEnd:(NSWindow *)panel
				returnCode:(int)returnCode
			   contextInfo:(NSArray *)objects;
-(IBAction)setupBaseColors:(id)sender;
-(void)setupClassControlColorsForCharacter:(NSManagedObject *)obj;
//-(void)setupBaseHPQuickForCharacter:(NSManagedObject *)obj;
//resting
-(IBAction)loadRestScreen:(id)sender;
-(IBAction)cancelRestScreen:(id)sender;
-(IBAction)restSelectedCharacters:(id)sender;
/*-(void)processTheHealingSpells:(NSArray *)healingSpells
				  onCharacters:(NSArray *)charsToRest
				byTheCharacter:(NSManagedObject *)obj
			 forTheClassNumber:(int)c
			withTheSpellLevels:(NSArray *)spellLevels
		  spellsAreSpontaneous:(BOOL)areSpont;*/
-(void)restTheCharacter:(NSManagedObject *)obj
			  toRestore:(BOOL)restore;
//haste/slow.
-(IBAction)enableHasted:(id)sender;
-(IBAction)enableSlowed:(id)sender;
//Add Character Methods.
-(IBAction)addNewCharacter:(id)sender;
-(IBAction)addNewQuickCharacter:(id)sender;
-(void)characterLockNowOn:(BOOL)lockChanged;
-(IBAction)characterLockChanged:(id)sender;
-(void)newCharacterSetupForChar:(NSManagedObject *)obj;
-(IBAction)closeQuickCharacter:(id)sender;
-(IBAction)closeQuickCharacterToSpells:(id)sender;
-(IBAction)closeQuickCharacterToAbilities:(id)sender;
-(IBAction)cancelQuickCharacter:(id)sender;
-(IBAction)addCharBattle:(id)sender;
-(IBAction)editCharBattle:(id)sender;
//Party Membership methods.
-(IBAction)addToMainParty:(id)sender;
-(void)addToMainPartyTheChar:(NSManagedObject *)obj;
-(IBAction)addToEnemyParty:(id)sender;
-(void)addToEnemyPartyTheChar:(NSManagedObject *)obj;
-(IBAction)removeFromMainParty:(id)sender;
-(NSString *)removeFromMainPartyTheChar:(NSManagedObject *)obj
							withMessage:(NSString *)message;
-(IBAction)removeFromEnemyParty:(id)sender;
-(NSString *)removeFromEnemyPartyTheChar:(NSManagedObject *)obj
							 withMessage:(NSString *)message;
-(NSManagedObject *)partyAddProcessing:(NSManagedObject *)obj;
//main window methods
-(IBAction)removeCharacter:(id)sender;
-(IBAction)duplicateCharacter:(id)sender;
-(IBAction)displayRollDiceSheet:(id)sender;
-(IBAction)displayGrantXPsheet:(id)sender;
-(IBAction)displayEditCharacterClassesSheet:(id)sender;
//Start Battle
-(IBAction)startBattle:(id)sender;
-(IBAction)continueBattle:(id)sender;
-(IBAction)exitBattle:(id)sender;
-(void)setupCharacterParties;
-(IBAction)renameParty1:(id)sender;
-(IBAction)renameParty2:(id)sender;
-(IBAction)renameSheetOKd:(id)sender;
-(IBAction)renameSheetCancelled:(id)sender;
-(void)renameSheetDidEnd:(NSWindow *)panel
			  returnCode:(int)returnCode
			 contextInfo:(NSManagedObject *)party;
-(IBAction)saveAsAParty1:(id)sender;
-(IBAction)saveAsAParty2:(id)sender;
-(void)saveAsAPartyWithMain:(BOOL)main
			   withNewParty:(NSManagedObject *)newParty;
-(IBAction)deleteParty1:(id)sender;
-(IBAction)deleteParty2:(id)sender;
-(IBAction)chooseForParty1:(id)sender;
-(IBAction)chooseForParty2:(id)sender;
-(void)chooseForPartyThatIsMain:(BOOL)main;
//weapon methods
-(void)updateDefaultWeapon;
-(IBAction)lightWeaponsChanged:(id)sender;
-(IBAction)setDefaultWeapon:(id)sender;
-(IBAction)setOffHandWeapon:(id)sender;
-(IBAction)cancelOffHandWeapon:(id)sender;
-(IBAction)addNewWeapon:(id)sender;
-(IBAction)removeWeapon:(id)sender;
-(IBAction)weaponHandedChanged:(id)sender;
-(IBAction)weaponABChanged:(id)sender;
-(void)weaponABChangedInCode;
-(IBAction)rangeIncrementSet:(id)sender;
-(IBAction)magicWeaponChanged:(id)sender;
-(IBAction)quickCriticalChanged:(id)sender;
//abilities
-(IBAction)skillValues:(id)sender;
-(IBAction)addNewSkill:(id)sender;
-(IBAction)crossClassPressed:(id)sender;
-(void)calculateRemainingSkillPointsForCharacter:(NSManagedObject *)obj;
-(IBAction)changeSkillClass:(id)sender;
-(IBAction)testAbility:(id)sender;
-(IBAction)armourCheckTest:(id)sender;
//testing abilities.
-(IBAction)searchCharactersForSkills:(id)sender;
-(IBAction)testCharacters:(id)sender;
-(IBAction)setUpFilters:(id)sender;
-(NSString *)filterButtonsPred;
//spells
-(IBAction)runAttackFromMainScreen:(id)sender;
-(IBAction)castSpellFromMainScreen:(id)sender;
-(IBAction)characterMagicScreen:(id)sender;
//portrait
-(void)openPanelDidEnd:(NSOpenPanel *)panel
			returnCode:(int)returnCode
		   contextInfo:(void *)x;
-(IBAction)loadPortrait:(id)sender;
//turn undead.
-(IBAction)updateTurnUndead:(id)sender;
//feats
-(BOOL)mightBeInCombatFeatShouldActivate:(NSManagedObject *)feat;
-(IBAction)activateFeat:(id)sender;
-(IBAction)featKeyChanged:(id)sender;
-(IBAction)featModChanged:(id)sender;
-(IBAction)featFeatWindowToOpen:(id)sender;
-(IBAction)featSpellWindowToOpen:(id)sender;
-(IBAction)featWeaponWindowToOpen:(id)sender;
-(IBAction)featToWeaponLinkSheetEnded:(id)sender;
-(IBAction)featToSpellLinkSheetEnded:(id)sender;
-(IBAction)featToFeatLinkSheetEnded:(id)sender;
-(void)featToFeatPanelEnded:(NSWindow *)panel
				 returnCode:(int)returnCode
				contextInfo:(NSManagedObject *)feat;
-(IBAction)featToSkillLinkSheetEnded:(id)sender;
-(IBAction)featUpdateUsesPerDay:(id)sender;
-(void)processFeatTable;
-(IBAction)configureFromFeatWeaponType:(id)sender;
-(IBAction)unlimitedFeatsChanged:(id)sender;
-(IBAction)addNewFeat:(id)sender;
-(IBAction)addNewAbility:(id)sender;
-(IBAction)xModifierChanged:(id)sender;
-(IBAction)featTypeChanged:(id)sender;
-(IBAction)featFilterChanged:(id)sender;
-(IBAction)featAffectsChanged:(id)sender;
-(IBAction)setupNoOfFeats:(id)sender;
//immunities.
-(IBAction)loadImmunitiesPanel:(id)sender;
-(IBAction)processImmunitiesOptions:(id)sender;
-(IBAction)closeImmunitiesPanel:(id)sender;
-(void)immunitiesPanelClosed:(NSWindow *)panel
				  returnCode:(int)returnCode
				 contextInfo:(NSWindow *)sendersWindow;
//check alignment and other misc methods.
- (NSArray*) objectsWithFetchRequest:(NSString*)entityType matchingPredicate:(NSPredicate*)predicate;
-(NSManagedObject *)createNewManagedObjectForName:(NSString *)str;
-(int)scoreToBonus:(NSNumber *)score;
+(BOOL)isGood:(NSManagedObject *)obj;
+(BOOL)isEvil:(NSManagedObject *)obj;
+(BOOL)isLawful:(NSManagedObject *)obj;
+(BOOL)isChaotic:(NSManagedObject *)obj;
//display log
-(void)displayLogSheet;
-(IBAction)closeLogSheet:(id)sender;
-(IBAction)clearLogSheet:(id)sender;
//delegate methods.
-(void)controlTextDidEndEditing:(NSNotification *)aNotification;
-(void)tableViewSelectionDidChange:(NSNotification *)notification;
-(void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem;
-(void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
-(void)characterStuffNeedsSettingUp;
-(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)aBool;
//- (void)textDidEndEditing:(NSNotification *)aNotification;
//table data view methods.
-(int)numberOfRowsInTableView:(NSTableView *)aTableView;
-(id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
		   row:(int)row;
//open file preferences.
-(IBAction)showFilePreferences:(id)sender;
-(IBAction)closeFilePreferences:(id)sender;
//battleStore.
-(NSManagedObject *)battleStore;
-(BOOL)setUpBattleStore;
-(NSManagedObject *)setUpSpellClassForCharClass:(NSManagedObject *)charClass;
-(void)setUpDomainClasses;
-(void)setUpCharacterClasses;
-(IBAction)cancelUpgradeToNewVersion:(id)sender;
-(IBAction)continueUpgradeToNewVersion:(id)sender;
-(IBAction)continueUpgradeToNewVersionAndDeleteOldVersion:(id)sender;
-(void)unsupportedDidEnd:(NSWindow *)panel
			  returnCode:(int)returnCode
			 contextInfo:(void *)contextInfo;
@end
